// packageA/pages/afterSale/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orders: [], // 原始订单数据
        filteredOrders: [], // 筛选后的订单
        searchText: '',
        dateText: '',
        shopText: '',
        statusText: '',
        shopList: [
          { id: 'all', name: '全部' },
          { id: 'shop1', name: '朝阳分店' },
          { id: 'shop2', name: '海淀分店' }
        ],
        statusList: [
          { id: 'all', name: '全部' },
          { id: 'pending', name: '待处理' },
          { id: 'returning', name: '退货中' },
          { id: 'completed', name: '已完成' },
          { id: 'rejected', name: '已拒绝' }
        ],
        showModal: false,
        currentOrder: null
    },
    loadOrders() {
        // 模拟数据加载
        // const orders = [...];
        const orders = [
            {
              id: '1001',
              orderNo: 'NO20250920001',
              applyTime: '2025-09-20 10:30',
              refundAmount: 58.00,
              receiver: {
                name: '张三',
                phone: '13800138000'
              },
              status: 'pending',
              statusText: '待处理',
              shop: 'shop1',
              handleTime: ''
            },
            {
              id: '1002',
              orderNo: 'NO20250919002',
              applyTime: '2025-09-19 15:20',
              refundAmount: 32.50,
              receiver: {
                name: '李四',
                phone: '13900139000'
              },
              status: 'returning',
              statusText: '退货中',
              shop: 'shop2',
              handleTime: '2025-09-20 09:15'
            }
          ];
        this.setData({ 
          orders,
          filteredOrders: orders 
        });
      },
    
      onSearchInput(e) {
        this.setData({ searchText: e.detail.value });
        this.filterOrders();
      },
    
      onDateChange(e) {
        this.setData({ dateText: e.detail.value });
        this.filterOrders();
      },
    
      onShopChange(e) {
        const index = e.detail.value;
        this.setData({ 
          shopText: this.data.shopList[index].name,
          selectedShop: this.data.shopList[index].id 
        });
        this.filterOrders();
      },
    
      onStatusChange(e) {
        const index = e.detail.value;
        this.setData({ 
          statusText: this.data.statusList[index].name,
          selectedStatus: this.data.statusList[index].id 
        });
        this.filterOrders();
      },
    
      filterOrders() {
        let filtered = this.data.orders;
        
        // 应用搜索条件
        if (this.data.searchText) {
          const search = this.data.searchText.toLowerCase();
          filtered = filtered.filter(o => 
            o.orderNo.includes(search) || 
            o.receiver.name.toLowerCase().includes(search) ||
            o.receiver.phone.includes(search)
          );
        }
        
        // 其他筛选条件...
        
        this.setData({ filteredOrders: filtered });
      },
    
      showDetail(e) {
        const id = e.currentTarget.dataset.id;
        const order = this.data.orders.find(o => o.id === id);
        this.setData({ 
          currentOrder: order,
          showModal: true 
        });
      },
    
      changeStatus(e) {
        const { id, status } = e.currentTarget.dataset;
        // 更新订单状态逻辑...
      },
    
      handleAction(e) {
        const action = e.currentTarget.dataset.action;
        this.setData({
            showModal:!this.data.showModal  
        })
        // 处理详情页操作...
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.loadOrders();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})